<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import attachment from '@/api/document/attachment'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()

const switchStatus = (statusValue, id, statusName) => {
  attachment.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'attachment',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: attachment.getList,
  edit: {
    show: true,
    api: attachment.update,
    auth: ['document:attachment:update']
  },
  delete: {
    show: true,
    api: attachment.deletes,
    auth: ['document:attachment:delete']
  },
  import: {
    show: true,
    url: 'document/attachment/import',
    templateUrl: 'document/attachment/downloadTemplate',
    auth: ['document:attachment:import']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "文件名",
    dataIndex: "filename",
    formType: "upload",
    type: "file",
    multiple: false
  },
  {
    title: "文件路径",
    dataIndex: "filepath",
    formType: "upload",
    type: "file",
    multiple: false
  },
  {
    title: "文件大小",
    dataIndex: "filesize",
    formType: "upload",
    type: "file",
    multiple: true
  },
  {
    title: "文件类型",
    dataIndex: "mime_type",
    formType: "input",
    search: true
  },
  {
    title: "关联id",
    dataIndex: "attachable_id",
    formType: "input",
    search: true
  },
  {
    title: "关联类型",
    dataIndex: "attachable_type",
    formType: "input",
    search: true
  },
  {
    title: "存储方式",
    dataIndex: "storage",
    formType: "input",
    search: true
  },
  {
    title: "用户是否可见",
    dataIndex: "user_visible",
    formType: "input",
    search: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'document:attachment' } </script>